//index.js
const Controllers = require('../../controllers/Controller.js').controller;
const app = getApp();
Page({
  data: {
    tabs: [
      {
        text: '全部',
        status: 0
      },
      {
        text: '待审核',
        status: 2
      },
      {
        text: '审核失败',
        status: 3
      }
    ],
    active: 0,
    list: []
  },
  onLoad(options) {
    var that = this;
    that.setData({
      active: parseInt(options.active) || 0
    })
  },
  onShow() {
    var that = this;
    that.myAgent();
  },
  changeTab(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.data.type = e.currentTarget.dataset.status;

    if (index !== that.data.active) {
      that.setData({
        active: index
      })
      that.myAgent();
    }
  },
  myAgent() {
    var that = this;
    wx.showLoading();
    var active = that.data.active;
    var tabs = that.data.tabs;
    var state = tabs[active].status;
    var params = {};
    if (state) {
      params.state = state;
    }
    Controllers.myAgent(params).then(res => {
      console.log('myAgent--res==', res);
      const { code, data, desc } = res;
      that.setData({
        list: data || []
      });
      wx.hideLoading()
    })
  },
  openPage(e) {
    var url = e.currentTarget.dataset.url;
    if (url) {
      app.openPage({ url });
    } else {
      wx.showToast({
        title: '未获取页面路径',
        icon: 'none'
      });
    }
  }
})